<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<script src="<c:url value='/static/jquery/jquery-1.9.1.min.js'/>" type="text/javascript"></script>

<title>新增消息</title>
</head>
<body>
	<div id="message"></div>
	<div class="panel panel-default">
		<div class="panel-body">
			<div class="row" style="margin-top:15px;">
				<div class="col-sm-8">
					<label class="col-sm-2 control-label">发布时间：</label>
					<div class="col-sm-10">
						${info.sendtime }
						<input type="hidden" class="form-control " id="sendTime"
											name="sendtime" value="${info.sendtime }" 
											>
					</div>
				</div>
			</div>
			<div class="row" style="margin-top:15px;">
				<div class="col-sm-8">
					<label class="col-sm-2 control-label">发布范围：</label>
					<div class="col-sm-10">
						<select id="scope" onChange="if(this.value=='3'){$('#row_id')[0].style.display='block'}else{$('#row_id')[0].style.display='none'}" 
						class="form-control">
							<option value="">请选择</option>
							<option value="0">全部</option>
							<option value="1">全部商家</option>
							<option value="2">全部买手</option>
							<option value="3">制定范围发布</option>
						</select>
					</div>
				</div>
			</div>
			<div class="row" id="row_id" style="margin-top:15px;display:none;">
				<div class="col-sm-8">
					<label class="col-sm-2 control-label">生财ID：</label>
					<div class="col-sm-10">
						<input id="ids" name="ids" class="form-control" />
					</div>
				</div>
			</div>
			<div class="row" style="margin-top:15px;">
				<div class="col-sm-8">
					<label class="col-sm-2 control-label">发布内容：</label>
					<div class="col-sm-10">
						<textarea id="sendContent" name="sendContent" class="form-control"
						name="auditOpinion" data-plugin-markdown-editor rows="10"></textarea>
					</div>
				</div>
			</div>
			<div class="row" style="margin-top:15px;">
				<div class="col-sm-8" style="padding-left:20%;">
						<button type="button" id="unaccess" class="btn btn-default btn-sm"
							style="width: 150px">取 消</button>
						<button type="button" id="access" class="btn btn-warning btn-sm"
							style="width: 150px">发 布</button>
				</div>
			</div>
		</div>
		<!-- panel-body -->
	</div>
	

	<script type="text/javascript">
		$(function($) {
			$('#unaccess').click(function() {
				history.go(-1);
			});

			$('#access').on("click",function() {
				var sendContent = $("#sendContent").val();
				if(!sendContent){
					showmessage("请填写消息内容！");
					return;
				}else if(sendContent.length>500){
					showmessage("消息内容超长！");
					return;
				}
				
				var sendTime = $("#sendTime").val();
				if(!sendTime){
					showmessage("请填写发布时间！");
					return;
				}
				var ids=$("#ids").val();
				var scope=$("#scope").val();
				if(!scope){
					showmessage("请选择发布范围！");
					return;
				}else if('3'==scope){
					if(!ids){
						showmessage("请输入生财id！");
						return;
					}
				}
				
				$.ajax({
					type : "post",
					url : path  + "/info/add",
					cache : false,
					data : {
						sendTime : new Date( sendTime.replace(/-/g,"/")),
						sendContent:sendContent,
						scope:scope,
						ids:ids.replace("，",","),
						_t : new Date().getTime()
					},
					dataType : "json",
					success : function(data) {
						if (data.success) {
							$('#access').off("click");
							showmessage(data.msg,function(){
								window.location.href=path+"/info/infoList"; 
							});
						}else{
							showmessage(data.msg);
						}
					}
				});
			});

		});
		
		
		//显示消息
		function showmessage(msg,callback){
			$('#message').ucMessage({
				msg:msg,
				callback:callback
			});
		}
	</script>
</body>
</html>